home *** CD-ROM | disk | FTP | other *** search
- Path: tera.com!miles
- From: miles@phobos.tera.com (Miles Ohlrich)
- Newsgroups: comp.lang.c++,comp.lang.fortran
- Subject: Re: Calling C++ from FORTRAN on VMS
- Date: 16 Feb 1996 09:46:44 -0800
- Organization: Tera Computer Company
- Sender: miles@Tera.COM
- Distribution: world
- Message-ID: <4g2fu4$o2p@phobos.tera.com>
- References: <31239D17.3159@stsci.edu>
- NNTP-Posting-Host: phobos.tera.com
-
-
- In article <31239D17.3159@stsci.edu>, Scott Stallcup <stallcup@stsci.edu> writes:
- |> I need to call a C++ routine from a FORTRAN routine on both
- |> VAX/VMS and AXP/VMS platforms.
- |>
- |> Given the following example code, what compiler/linker options
- |> will resolve the c++ reference ?
- |>
- |> ---------------------------------------------------------------
- |> program tfor
- |> c
- |> call tcxx ()
- |> c
- |> end
- |> ---------------------------------------------------------------
- Try this:
-
- #include <stdio.h>
- extern "C" void TCXX();
- void TCXX(void) {
- printf ("Hello World\n");
- }
-
- or this:
-
- #include <stdio.h>
- extern "C" void tcxx_();
- void tcxx_(void) {
- printf("Hello World\n");
- }
-
- Different platforms convert fortran function names differently: some convert
- to all caps; some add an underscore after the name.
- If you are doing mixed language programming on two separate platforms that
- use different naming conventions, you may have to use #ifdefs in the C++ code
- such as:
-
- #include <stdio.h>
- #ifdef __sun__
- extern "C" void tcxx_();
- void tcxx_(void) {
- printf("Hello World\n");
- }
- #else
- extern "C" void TCXX();
- void TCXX(void) {
- printf("Hello World\n");
- }
- #endif
-
- Note that you need the extern "C" line so that C++ doesn't do name mangling on
- the function name.
- I am not familiar with your specific platforms, however.
-
- Miles Ohlrich
- Tera Computer Company
-